//
//  LGCancerPatientDetailCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2024/7/9.
//

#import "LGCancerPatientDetailCell.h"
#import "LGCheckPhotoTool.h"
@interface LGCancerPatientDetailCell()
/**   */
@property (nonatomic , strong)UIView *backView;
/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)UILabel *leftTime;
/**   */
@property (nonatomic , strong)UILabel *rightTime;
/**   */
@property (nonatomic , strong)UILabel *photoTitle;
/**   */
@property (nonatomic , strong)UIImageView *photoView;
/**   */
@property (nonatomic , strong)NSArray *photoArray;

@end

@implementation LGCancerPatientDetailCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.type = LGPositionTypeMiddle;
        [self createSubView];
    }
    return  self;
}

//治疗
-(void)setDataDic:(NSDictionary *)dataDic{
    [super setDataDic:dataDic];
    // 1-手术、 2-放疗、 3-化疗、 4-靶向治疗、 5-免疫治疗、 6-内分泌治疗、 7-中医治疗、 8-介入治疗、 9-其他治疗
    NSString *type = LGNSString(dataDic[@"treat_type"]);
    NSString *timeTitle = @"入院日期";
    if ([type integerValue]>0) {
        timeTitle = ([type isEqualToString:@"1"]||[type isEqualToString:@"2"])?@"手术日期":@"开始日期";
    }
    NSString *title = @"";
    if ([type isEqualToString:@"1"]) {
        title = @"手术";
    }else if ([type isEqualToString:@"2"]){
        title = LGNSString(dataDic[@"radiotherapy_type"]);
    }else if ([type isEqualToString:@"3"] || [type isEqualToString:@"4"]||[type isEqualToString:@"5"]){
        title = LGNSString(dataDic[@"medicine_name"]);
    }else{
        title = (LGNSString(dataDic[@"other_title"]).length>0)?LGNSString(dataDic[@"other_title"]):LGNSString(dataDic[@"title"]);
    }
    
    self.titleLabel.text = title;
    //开始、结束时间
    NSString *startTime = LGNSString(dataDic[@"start_date"]);
    self.leftTime.text = [NSString stringWithFormat:@"%@  %@",timeTitle,startTime];
    
    NSString *endTime = LGNSString(dataDic[@"end_date"]);
    NSString *endTitle = ([type integerValue]<0)?@"出院日期":@"结束日期";
    self.rightTime.text = (endTime.length>6)?[NSString stringWithFormat:@"%@  %@",endTitle,endTime]:@"";
    //图片
    NSArray *photoArray = dataDic[@"files"];
    self.photoArray = photoArray;
    self.photoTitle.text = (photoArray.count>0)?@"处方图片":@"";
    self.photoTitle.hidden = (photoArray.count>0)?NO:YES;
    self.photoView.hidden = (photoArray.count>0)?NO:YES;
    if (photoArray.count>0) {
        [self.photoView sd_setImageWithURL:[NSURL URLWithString:LGNSString(photoArray[0])]];
    }
    
    CGFloat timeTop = (title.length>0)?viewPix(8):viewPix(2);
    CGFloat bottom = (photoArray.count>0)?-viewPix(156):-viewPix(10);
    [self.leftTime mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).offset(timeTop);
        make.bottom.equalTo(self.backView).offset(bottom);
    }];
}

//出院小结
-(void)setReportDic:(NSDictionary *)reportDic{
    _reportDic = reportDic;
    
}

-(void)checkAllPhotos{
    LGCheckPhotoTool *photoView = [[LGCheckPhotoTool alloc]initWithFrame:CGRectMake(0, 0, Screen_W, Screen_H)];
    photoView.picArray = self.photoArray;
    [[ObjectTool mainWindow] addSubview:photoView];
    [photoView showViewAnimation:CGPointMake(0, 0) index:0];
}

#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    [self.contentView addSubview:self.backView];
    [self.backView addSubview:self.titleLabel];
    [self.backView addSubview:self.leftTime];
    [self.backView addSubview:self.rightTime];
    [self.backView addSubview:self.photoTitle];
    [self.backView addSubview:self.photoView];
    [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(viewPix(3));
        make.bottom.equalTo(self.contentView).offset(-viewPix(7));
        make.left.equalTo(self.contentView).offset(viewPix(28));
        make.right.equalTo(self.contentView).offset(-viewPix(28));
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(self.backView).offset(viewPix(10));
        make.right.equalTo(self.backView).offset(-viewPix(10));
    }];
    [self.leftTime mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).offset(viewPix(8));
        make.left.equalTo(self.titleLabel);
        make.bottom.equalTo(self.backView).offset(-viewPix(10));
    }];
    [self.rightTime mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.backView).offset(viewPix(170));
        make.centerY.equalTo(self.leftTime);
    }];
    [self.photoTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.leftTime.mas_bottom).offset(viewPix(18));
        make.left.equalTo(self.titleLabel);
    }];
    [self.photoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.photoTitle.mas_bottom).offset(viewPix(8));
        make.left.equalTo(self.photoTitle);
        make.width.equalTo(@(viewPix(187)));
        make.height.equalTo(@(viewPix(101)));
    }];
}

-(UIView *)backView{
    if(!_backView){
        _backView = [[UIView alloc]init];
        _backView.backgroundColor = [UIColor colorWithString:@"#FAFAFA"];
        [_backView addBorder:@"#E3E3E3" lineWidth:1 cornerRidus:5];
    }
    return _backView;
}

-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"" colorString:@"#282828" textFont:LGFontWeight(15, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:0];
    }
    return _titleLabel;
}

-(UILabel *)leftTime{
    if(!_leftTime){
        _leftTime = [UILabel lableWithText:@"" colorString:@"#909399" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _leftTime;
}

-(UILabel *)rightTime{
    if(!_rightTime){
        _rightTime = [UILabel lableWithText:@"" colorString:@"#909399" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _rightTime;
}

-(UILabel *)photoTitle{
    if(!_photoTitle){
        _photoTitle = [UILabel lableWithText:@"" colorString:@"#282828" textFont:LGFontWeight(15, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _photoTitle;
}

-(UIImageView *)photoView{
    if(!_photoView){
        _photoView = [[UIImageView alloc]init];
        _photoView.contentMode = UIViewContentModeScaleAspectFill;
        _photoView.clipsToBounds = YES;
        _photoView.userInteractionEnabled = YES;
        [_photoView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(checkAllPhotos)]];
    }
    return _photoView;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
